<template>
    <div>
        <div>应用返回页。接code: {{ code }}</div>

        <el-input v-model="$data.host">
            <template slot="prepend">Oauth服务器地址</template>
        </el-input>

        <el-button @click="code2token_click">code换token</el-button>

        <div v-if="$data.token">token: {{ $data.token }}</div>
        <el-button @click="token_get_user_click">用token拿用户信息</el-button>
        <div v-if="$data.userInfo">用户信息： {{ $data.userInfo }}</div>
    </div>
</template>

<script setup>




defineOptions({
    name: "app3",
    inheritAttrs: true,
});

//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({"host":"http://192.168.5.213/api/mp-iam-admin-api","code":"","token":{},"userInfo":""});


const $props = defineProps({

});





const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);



const code2token_click = function() {
    jv.$http.post($data.host + "/oauth/code2token?code=" + $data.code).then(res => {
        var token = res.data.data;
        $data.token = token;
    });
};
const token_get_user_click = function() {
    jv.$http.get($data.host +"/oauth/user-info?token=" + $data.token.token).then(res => {
        var userInfo = res.data.data;
        $data.userInfo = JSON.stringify(userInfo);
    });
};

onMounted( function() {
    $data.code = jv.$route.query["code"];
} )




</script>
